package simbot.example;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import freemarker.template.TemplateException;
import love.forte.simbot.LongID;
import love.forte.simbot.component.mirai.event.MiraiReceivedMessageContent;
import love.forte.simbot.component.mirai.message.MiraiSendOnlyImage;
import love.forte.simbot.definition.Group;
import love.forte.simbot.resources.PathResource;
import love.forte.simbot.resources.Resource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.hibernate.jpa.HibernateHints;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import simbot.example.entity.*;
import simbot.example.listener.MyGroupListener;
import simbot.example.mapper.*;
import simbot.example.util.*;
import simbot.example.util.HttpUtil;
import simbot.example.util.QuFuUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static simbot.example.util.GenerateImageUtil.generateSizeImage;
import static simbot.example.util.GenerateImageUtil.generateSizeImageJiaoYiHang;

/**
 * Mybatis 代理开发
 */
public class MyBatisDemo2 {
    public static void main(String[] args) throws IOException {
        Param param = QuFuUtil.getParam("xiaoshuo");
        String s = HttpUtil.getBase64FromUrl("https://www.buquwu.com/api/search.php?novel=全职高手");
        Integer size=10;
        if(ObjectUtil.isNotEmpty("20")){
            size=Integer.parseInt("20");
        }
        JSONObject json = JSONObject.parseObject(s);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code"))) {
            JSONArray ja = (JSONArray) json.get("novels");
            List<Map> maps = ja.toJavaList(Map.class);
            if(maps.size()<size){
                size=maps.size();
            }

            String context="";
            for (Integer i = 0; i < size; i++) {
                context=context+ i+".书名："+maps.get(i).get("title")+"\n作者："+maps.get(i).get("author")+"\nurl："
                        +maps.get(i).get("url")+"\n";
            }
            System.out.println(context);
        }
    }

    //吃什么
    public static void main35(String[] args) throws IOException {

        Param param = QuFuUtil.getParam("chishenmo");
        String s = HttpUtil.get(param.getValue());
        JSONObject json = JSONObject.parseObject(s);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code"))) {
            System.out.println("1."+json.getString("meal1")+"\n"+"2."+json.getString("meal2")+"\n"+json.getString("mealwhat"));
            return;
        }
    }

    //表情包
    public static void main34(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        HeChengMapper heChengMapper = sqlSession.getMapper(HeChengMapper.class);
        //获取消息成员
        List<String> avatarList =new ArrayList<>();
        avatarList.add("https://th.bing.com/th/id/OIP.vLIoYMoka_8FHMurmGyKlwAAAA?pid=ImgDet&rs=1");
        avatarList.add("https://th.bing.com/th/id/R.b7991ceefcfc90c4473b3f6f2444f718?rik=4G1coybQTU0mWg&riu=http%3a%2f%2fdocs.oracle.com%2fjavase%2f7%2fdocs%2ftechnotes%2fguides%2f2d%2fspec%2fimages%2ft606a8.jpg&ehk=0ROTIIBJhu0J5kX1ft8bfeh%2b7gJHR7YoG%2fPoA9QjNCw%3d&risl=&pid=ImgRaw&r=0");

        String key = "没有世俗的欲望";

        UUID uuid = UUID.randomUUID();
        String path = "src/main/resources/image/" + uuid.toString();


        HeCheng heCheng = heChengMapper.selectByKey(key);
        String address = heCheng.getAddress();
        String type = heCheng.getType();
        String json = heCheng.getJson();
        int with = heCheng.getWith();
        int high = heCheng.getHigh();
        sqlSession.close();
        List<ZuoBiao> list = JSON.parseArray(json,ZuoBiao.class);
        path=path+"."+type;
        if ("gif".equals(type)) {

        }else {
            for (int i = 0; i < list.size(); i++) {
                with=ObjectUtil.isNotEmpty(list.get(i).getWith())?list.get(i).getWith():with;
                high=ObjectUtil.isNotEmpty(list.get(i).getHigh())?list.get(i).getHigh():high;
                if(with!=0&&high!=0) {
                    ImageServiceImpl.imageWatermark(avatarList.get(i), address, path,
                            Integer.parseInt(list.get(i).getX()), Integer.parseInt(list.get(i).getY()), 1, with, high);
                    address = path;
                }
            }
        }
        //发送图片
        PathResource resource1 = Resource.of(Paths.get(path));
        MiraiSendOnlyImage sendOnlyImage = MiraiSendOnlyImage.of(resource1);
        System.out.println(sendOnlyImage);
    }

    public static void main33(String[] args) throws IOException {
        // float alpha=1;
        // imageWatermark("src/main/resources/heCheng/image/touxiang.jpg","src/main/resources/heCheng/image/luoshifen.jpg","src/main/resources/heCheng/image/3.jpg",
        //         200,150,alpha);
        // imageWatermark("src/main/resources/heCheng/image/touxiang.jpg","src/main/resources/heCheng/image/3.jpg","src/main/resources/heCheng/image/3.jpg",
        //         360,680,alpha);



        // //透明度
        // float alpha=1;
        // //位置
        //
        List<ZuoBiao> list =new ArrayList<>();
        list.add(new ZuoBiao("200","150"));
        list.add(new ZuoBiao("360","680"));


        String s = JSON.toJSONString(list);
        System.out.println(s);
        List<ZuoBiao> parse = (List<ZuoBiao>)JSON.parse(s);
        System.out.println(parse);
        // for (int i = 0; i < zuobiao.length; i++) {

        // }
        // //头像宽高
        // int markImageWidth = 50;
        // int markImageHeight = 50;
        // //gif地址
        // String gifAdress="1.gif";
        // //头像地址
        // String touxiangAdress="2.jpg";
        // //导出位置
        // String exportAdress="3.gif";
        // heChengTuPian(markImageWidth,markImageHeight,gifAdress,touxiangAdress,exportAdress,alpha,zuobiao);
    }

    /**
     * 给图片添加图片水印
     * @param pressImg       水印图片
     * @param localImagePath 源图像地址
     * @param pressImageFile 目标图像地址
     * @param x              修正值。 默认在中间
     * @param y              修正值。 默认在中间
     * @param alpha          透明度,必须是范围 [0.0, 1.0] 之内（包含边界值）的一个浮点数字,值越小透明度越高
     * @throws IOException   IOException
     */
    public static void imageWatermark(String pressImg, String localImagePath, String pressImageFile, int x, int y, float alpha) throws IOException {
        //源文件
        File localFile = new File(localImagePath);
        if (ObjectUtils.isEmpty(localFile)){
            throw new IllegalArgumentException("未找到图片");
        }
        Image localImage = ImageIO.read(localFile);
        int width = localImage.getWidth(null);
        int height = localImage.getHeight(null);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = image.createGraphics();
        graphics.drawImage(localImage, 0, 0, width, height, null);


        // 水印文件
        BufferedImage pressImg1 = ImageIO.read( new  FileInputStream(pressImg) );
        BufferedImage bufferedImage1 = scaleByPercentage(pressImg1, 200, 200);
        BufferedImage bufferedImage = cutHeadImages(bufferedImage1);
        int markImageWidth = bufferedImage.getWidth(null);
        int markImageHeight = bufferedImage.getHeight(null);
        // 将新像素与图形处理器上的现有像素组合
        graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
        // 矩形图像原点为左上角,x,y=0,图片水印在源图中间
        // x为原点在水平距离向右的修正值，x为原点在垂直距离向下的修正值
        graphics.drawImage(bufferedImage, x, y, markImageWidth, markImageHeight, null);
        // 释放图形处理资源
        graphics.dispose();
        ImageIO.write(image,  "jpg", new File(pressImageFile));
    }

    //将图片变为圆
    public static BufferedImage cutHeadImages(BufferedImage avatarImage) {
        try {
            int width = avatarImage.getWidth();
            // 透明底的图片
            BufferedImage formatAvatarImage = new BufferedImage(width, width, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D graphics = formatAvatarImage.createGraphics();
            //把图片切成一个园
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            //留一个像素的空白区域，这个很重要，画圆的时候把这个覆盖
            int border = 1;
            //图片是一个圆型
            Ellipse2D.Double shape = new Ellipse2D.Double(border, border, width - border * 2, width - border * 2);
            //需要保留的区域
            graphics.setClip(shape);
            graphics.drawImage(avatarImage, border, border, width - border * 2, width - border * 2, null);
            graphics.dispose();
            //在圆图外面再画一个圆
            //新创建一个graphics，这样画的圆不会有锯齿
            graphics = formatAvatarImage.createGraphics();
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            int border1 = 3;
            //画笔是4.5个像素，BasicStroke的使用可以查看下面的参考文档
            //使画笔时基本会像外延伸一定像素，具体可以自己使用的时候测试
            Stroke s = new BasicStroke(5F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            graphics.setStroke(s);
            graphics.setColor(Color.WHITE);
            graphics.drawOval(border1, border1, width - border1 * 2, width - border1 * 2);
            graphics.dispose();
            return formatAvatarImage;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 缩小Image，此方法返回源图像按给定宽度、高度限制下缩放后的图像
     *
     * @param inputImage
     *            ：压缩后宽度
     *            ：压缩后高度
     * @throws java.io.IOException
     *             return
     */
    public static BufferedImage scaleByPercentage(BufferedImage inputImage, int newWidth, int newHeight){
        // 获取原始图像透明度类型
        try {
            int type = inputImage.getColorModel().getTransparency();
            int width = inputImage.getWidth();
            int height = inputImage.getHeight();
            // 开启抗锯齿
            RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            // 使用高质量压缩
            renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            BufferedImage img = new BufferedImage(newWidth, newHeight, type);
            Graphics2D graphics2d = img.createGraphics();
            graphics2d.setRenderingHints(renderingHints);
            graphics2d.drawImage(inputImage, 0, 0, newWidth, newHeight, 0, 0, width, height, null);
            graphics2d.dispose();
            return img;

        }catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    // public static void heChengTuPian( String gifAddress,String touxiangAdress,String exportAdress,float alpha,Integer[][] zuobiao) throws IOException {
    //
    //
    //     //gif读取
    //     try{
    //         GifDecoder gd = new GifDecoder();
    //         int status = gd.read(new FileInputStream(new File("src/main/resources/gif/"+gifAddress)));
    //         if (status != GifDecoder.STATUS_OK) {
    //             return;
    //         }
    //
    //         List<BufferedImage> frames = new ArrayList<>();
    //         for (int i = 0; i < gd.getFrameCount(); i++) {
    //             BufferedImage frame = gd.getFrame(i);
    //             int t = gd.getDelay(i);
    //             Graphics2D graphics = frame.createGraphics();
    //             graphics.drawImage(frame, 0, 0, frame.getWidth(), frame.getHeight(), null);
    //
    //             int markImageWidth = markImage.getWidth(null);
    //             int markImageHeight = markImage.getHeight(null);
    //             // 将新像素与图形处理器上的现有像素组合
    //             graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
    //             // 矩形图像原点为左上角,x,y=0,图片水印在源图中间
    //             // x为原点在水平距离向右的修正值，x为原点在垂直距离向下的修正值
    //             graphics.drawImage(markImage, zuobiao[i][0], zuobiao[i][1], markImageWidth, markImageHeight, null);
    //             // 释放图形处理资源
    //             graphics.dispose();
    //             frames.add(frame);
    //         }
    //
    //         File output = new File("src/main/resources/gif/"+exportAdress);
    //         AnimatedGifEncoder e = new AnimatedGifEncoder();
    //         e.start(new FileOutputStream(output));
    //         e.setDelay(1000 / 24);   // 1 frame per sec
    //         for (BufferedImage image : frames) {
    //             e.addFrame(image);
    //         }
    //         e.finish();
    //
    //     }catch(Exception e){
    //         e.printStackTrace();
    //     }
    // }

    //八卦
    public static void main21(String[] args) throws IOException {
        String token = QuFuUtil.getParam("token").getValue();
        String[] ci = {"818", "616", "树洞", "记录", "教程", "街拍", "故事", "避雷", "吐槽", "提问"};
        //获取参数
        Param param = QuFuUtil.getParam("bagua");
        //获取消息
        String result = HttpUtil.get(param.getValue() + "?&token=" + token + "&server=" + "&subclass=818" + "&limit=1");
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            String type = "";
            String server = "";
            String title = "";
            String url = "";
            List<Map> list = JSONArray.parseArray(json.getString("data"), Map.class);
            for (Map map : list) {
                type = map.get("subclass").toString();
                server = map.get("server").toString();
                title = map.get("title").toString();
                url = "https://tieba.baidu.com/p/" + map.get("url").toString() + "?frwh=index";
            }
            System.out.println(server + "--[" + type + "]" + "\n" +
                    title + "\n" +
                    url);
        } else {
        }
    }

    //物价
    public static void main25(String[] args) throws TemplateException, IOException {
        //获取参数
        String url = "https://www.jx3api.com/data/trade/record?name=河汉清云&token=v184a0829deb368fde";
        String result = HttpUtil.get(url);
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            Map<String, Object> dict = JSON.parseObject(json.getString("data"), Map.class);
            List<Map<String, Object>> li = new ArrayList<>();
            if (ObjectUtil.isNotEmpty(dict.get("data"))) {
                List data = JSON.parseObject(dict.get("data").toString(), List.class);
                for (Object datum : data) {
                    List<Map> list = JSONArray.parseArray(datum.toString(), Map.class);
                    if (ObjectUtil.isNotEmpty(list) && list.size() > 0) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("name", list.get(0).get("class"));
                        map.put("list", list);
                        li.add(map);
                    }
                    for (Map map1 : list) {
                        if ("1".equals(map1.get("sales").toString())) {
                            map1.put("sales", "出售");
                        } else if ("2".equals(map1.get("sales").toString())) {
                            map1.put("sales", "收购");
                        } else if ("3".equals(map1.get("sales").toString())) {
                            map1.put("sales", "想出");
                        } else if ("4".equals(map1.get("sales").toString())) {
                            map1.put("sales", "想收");
                        } else if ("5".equals(map1.get("sales").toString())) {
                            map1.put("sales", "成交");
                        } else if ("6".equals(map1.get("sales").toString())) {
                            map1.put("sales", "正出");
                        } else if ("7".equals(map1.get("sales").toString())) {
                            map1.put("sales", "公示");
                        }
                    }
                }
            }
            dict.put("li1", li.subList(0, li.size() / 2));
            dict.put("li2", li.subList(li.size() / 2, li.size()));
            //生成图片
            ModelMap modelMap = new ModelMap();
            modelMap.put("resume", dict);
            String templateName = "wujia.ftl";
            String html = FreemarkeTools.ftlToString(modelMap, templateName);
            String htmlFilePath = "src/main/resources/html/wujia.html";
            UUID uuid = UUID.randomUUID();
            String imageFilePath = "src/main/resources/image/" + uuid.toString() + ".jpg";
            String imgPath = FreemarkeTools.turnImage(html, htmlFilePath, imageFilePath, 800, 1300);
            // 构建图片
            PathResource resource1 = Resource.of(Paths.get(imgPath));
            MiraiSendOnlyImage offlineImage = MiraiSendOnlyImage.of(resource1);
        } else {

        }
    }

    //名剑
    public static void main24(String[] args) throws TemplateException, IOException {
        String url = "https://www.jx3api.com/data/match/recent" + "?&token=" + "v184a0829deb368fde" + "&server=" + "梦江南" + "&ticket=" + "02a8bd5f245e48268bfaf728115a45d5:wsddysy:kingsoft::enNwc2VleTh2cHh0NWdscw==" + "&mode=33" + "&name=" + "韶辞辞";
        String result = HttpUtil.get(url);
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            Map<String, Object> dict = JSON.parseObject(json.getString("data"), Map.class);
            if (ObjectUtil.isNotEmpty(dict.get("performance"))) {
                Map<String, Object> dict1 = JSON.parseObject(dict.get("performance").toString(), Map.class);
                dict.put("san", dict1.get("3v3"));
                dict.put("wu", dict1.get("5v5"));
                dict.put("er", dict1.get("2v2"));
            }
            if (StringUtils.isEmpty(dict.get("san"))) {
                dict.put("san", new HashMap<>());
            }
            if (StringUtils.isEmpty(dict.get("er"))) {
                dict.put("er", new HashMap<>());
            }
            if (StringUtils.isEmpty(dict.get("wu"))) {
                dict.put("wu", new HashMap<>());
            }
            List<Map> list = JSON.parseArray(dict.get("history").toString(), Map.class);
            for (Map map : list) {
                Long startTime = Long.parseLong(map.get("startTime").toString());
                Long endTime = Long.parseLong(map.get("endTime").toString());
                Long time = endTime - startTime;
                map.put("time", time);
                Date date = new Date(endTime * 1000);
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String time1 = sd.format(date);
                map.put("endDay", time1);
                String won = "";
                if ("true".equals(map.get("won").toString())) {
                    won = "胜利";
                } else {
                    won = "失败";
                }
                if ("true".equals(map.get("mvp").toString())) {
                    won = won + ":mvp";
                }
                map.put("result", won);
            }
            dict.put("history", list);
            //生成图片
            ModelMap modelMap = new ModelMap();
            modelMap.put("resume", dict);
            String templateName = "mingjian.ftl";
            String html = FreemarkeTools.ftlToString(modelMap, templateName);
            String htmlFilePath = "src/main/resources/html/mingjian.html";
            UUID uuid = UUID.randomUUID();
            String imageFilePath = "src/main/resources/image/" + uuid.toString() + ".jpg";
            String imgPath = FreemarkeTools.turnImage(html, htmlFilePath, imageFilePath, 1000, 1000);
            // 构建图片
            PathResource resource1 = Resource.of(Paths.get(imgPath));
            MiraiSendOnlyImage offlineImage = MiraiSendOnlyImage.of(resource1);

            System.out.println(offlineImage);
        } else {
        }
    }

    //金价
    public static void main23(String[] args) throws TemplateException, IOException {
        String server = "";
        String url = "https://www.jx3api.com/data/trade/demon?server=长安城&limit=2";
        String result = HttpUtil.get(url);
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            List<Map> list = JSON.parseArray(json.getString("data").toString(), Map.class);
            String jin = server + "金价：";
            for (Map map : list) {
                if (ObjectUtil.isNotEmpty(map.get("wanbaolou"))) {
                    jin = jin + "\n" + "万宝楼：" + map.get("wanbaolou").toString();
                }
                if (ObjectUtil.isNotEmpty(map.get("tieba"))) {
                    jin = jin + "\n" + "贴吧：" + map.get("tieba").toString();
                }
                if (ObjectUtil.isNotEmpty(map.get("dd373"))) {
                    jin = jin + "\n" + "dd373：" + map.get("dd373").toString();
                }
                if (ObjectUtil.isNotEmpty(map.get("5173"))) {
                    jin = jin + "\n" + "5173：" + map.get("5173").toString();
                }
                if (ObjectUtil.isNotEmpty(map.get("uu898"))) {
                    jin = jin + "\n" + "uu898：" + map.get("uu898").toString();
                }
                break;
            }
            System.out.println(jin);
        }
    }

    //cd查询
    public static void main22(String[] args) throws IOException, TemplateException {
        ;
        String url = "https://www.jx3api.com/data/role/teamCdList" + "?&token=" + "v184a0829deb368fde" + "&server=" + "梦江南" + "&ticket=" + "02a8bd5f245e48268bfaf728115a45d5:wsddysy:kingsoft::enNwc2VleTh2cHh0NWdscw==" + "&name=" + "韶辞辞" + "&robot=" + "添只饺子";
        String result = HttpUtil.get(url);
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            Map<String, Object> dict = JSON.parseObject(json.getString("data"), Map.class);
            if (ObjectUtil.isNotEmpty(dict.get("data"))) {
                List<Map> list = JSON.parseArray(dict.get("data").toString(), Map.class);
                for (Map map : list) {
                    String finBoss = "";
                    String unBoss = "";
                    if (ObjectUtil.isNotEmpty(map.get("bossProgress"))) {
                        List<Map> list1 = JSON.parseArray(map.get("bossProgress").toString(), Map.class);
                        for (Map map1 : list1) {
                            String s = map1.get("finished").toString();
                            if ("true".equals(map1.get("finished").toString())) {
                                finBoss = finBoss + "-" + map1.get("name");
                            } else {
                                unBoss = unBoss + "/" + map1.get("name");
                            }
                        }
                    }
                    map.put("finBoss", finBoss);
                    map.put("unBoss", unBoss);
                }
                dict.put("data", list);
            }
            //生成图片
            ModelMap modelMap = new ModelMap();
            modelMap.put("resume", dict);
            String templateName = "cd.ftl";
            String html = FreemarkeTools.ftlToString(modelMap, templateName);
            String htmlFilePath = "src/main/resources/html/resume.html";
            UUID uuid = UUID.randomUUID();
            String imageFilePath = "src/main/resources/image/" + uuid.toString() + ".jpg";
            String imgPath = FreemarkeTools.turnImage(html, htmlFilePath, imageFilePath, 1000, 1000);
            // 构建图片
            PathResource resource1 = Resource.of(Paths.get(imgPath));
            MiraiSendOnlyImage offlineImage = MiraiSendOnlyImage.of(resource1);

            System.out.println(offlineImage);
        } else {
            System.out.println("查询失败 累了 毁灭吧");
        }
    }

    //翻译
    public static void main4(String[] args) throws IOException, InterruptedException {
        String wenben = "翻译 The hour hand of a clock can go back to the starting point ,but it was not yesterday any more .";
        String substring = wenben.substring(3, wenben.length());
        //获取参数
        Param param = QuFuUtil.getParam("fanyi");
        String s = HttpRequest.sendGet(param.getValue(), "text=" + substring);
        String s1 = substring.replaceAll(" ", "%20");
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(s);
        if (!StringUtils.isEmpty(json.getString("success")) && json.getString("success").equals("true") && !StringUtils.isEmpty(json.getString("data"))) {
            String data = json.getString("data");
            final JSONObject json1 = JSONObject.parseObject(data);
            String fanyi = json1.getString("fanyi");
            System.out.println(fanyi);
        } else {

        }
    }

    //微博
    public static void main13(String[] args) throws IOException, InterruptedException {
        //获取参数
        Param param = QuFuUtil.getParam("weibo");
        String s = HttpRequest.sendGet(param.getValue(), null);
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(s);
        if (!StringUtils.isEmpty(json.getString("success")) && json.getString("success").equals("true") && !StringUtils.isEmpty(json.getString("data"))) {
            String list = json.getString("data");
            List<WeiBo> zhuaMaDtoList = (List<WeiBo>) JSONArray.parseArray(list, WeiBo.class);
            String text = "微博热搜：";
            for (int i = 0; i < 15; i++) {
                text = text + "\n" + zhuaMaDtoList.get(i).getTitle();
            }
            System.out.println(text);
        } else {
        }
    }

    //setu
    public static void main12(String[] args) throws IOException, InterruptedException {
        //获取参数
        Param param = QuFuUtil.getParam("setu");
        String result = HttpUtil.get(param.getValue() + "?r18=0");
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!StringUtils.isEmpty(json.getString("data"))) {
            String list = json.getString("data");
            List<SeTu> zhuaMaDtoList = (List<SeTu>) JSONArray.parseArray(list, SeTu.class);
            for (SeTu seTu : zhuaMaDtoList) {
                Map<String, String> urls = seTu.getUrls();
                String url = urls.get("original");
                MiraiSendOnlyImage offlineImage = MiraiSendOnlyImage.of(Resource.of(new URL(url)));
                System.out.println(url);
            }
        } else {
        }
    }

    //早报
    public static void main10(String[] args) throws IOException, InterruptedException {
        Param zaobao = QuFuUtil.getParam("zaobao");
        Param zaobaotoken = QuFuUtil.getParam("zaobaotoken");
        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3. 获取mapper
        GroupQuMapper mapper = sqlSession.getMapper(GroupQuMapper.class);
        List<GroupQu> groupQus = mapper.selectAllzaobao();
        sqlSession.close();
        String s = HttpUtil.get(zaobao.getValue() + "?token=" + zaobaotoken.getValue() + "&format=json");
        final JSONObject json = JSONObject.parseObject(s);
        String data = json.getString("data");
        if (!ObjectUtils.isEmpty(data)) {
            final JSONObject json1 = JSONObject.parseObject(data);
            String url = json1.getString("image");
            // 构建图片
            MiraiSendOnlyImage offlineImage = MiraiSendOnlyImage.of(Resource.of(new URL(url)));
            for (GroupQu groupQu : groupQus) {
                // MiraiGroup group = miraiBot.getGroup(Identifies.ID(groupQu.getGroupId()));
                // group.sendBlocking(offlineImage);
            }
        }
    }

    //抓马播报
    public static void main11(String[] args) throws IOException, InterruptedException {
        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3. 获取mapper
        GroupQuMapper mapper = sqlSession.getMapper(GroupQuMapper.class);
        MessageLogMapper messageLogMapper = sqlSession.getMapper(MessageLogMapper.class);
        List<GroupQu> groupQus = mapper.selectAll();

        Map<String, List<GroupQu>> collect1 = groupQus.stream().collect(Collectors.groupingBy(p -> p.getQu(), Collectors.toList()));
        Set<String> fuList = collect1.keySet();
        for (String fu : fuList) {
            Param param = QuFuUtil.getParam("zhuama");
            String url = param.getValue() + "?pageIndex=1&pageSize=50&server=" + fu + "&type=horse";
            String result = HttpUtil.get(url);
            final JSONObject json = JSONObject.parseObject(result);
            String data = json.getString("data");
            final JSONObject json1 = JSONObject.parseObject(data);
            String list = json1.getString("list");
            List<ZhuaMaDto> zhuaMaDtoList = (List<ZhuaMaDto>) JSONArray.parseArray(list, ZhuaMaDto.class);

            String message = "";
            //获取时间戳(十分钟前的)
            long time = System.currentTimeMillis() - 60000 * 10;
            List<ZhuaMaDto> collect = zhuaMaDtoList.stream().filter(p -> "zhcn_hd".equals(p.getEdition()) && p.getTime() * 1000 > time).collect(Collectors.toList());
            //5-10分钟播报
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            for (ZhuaMaDto zhuaMaDto : collect) {
                MessageLog messageLog = messageLogMapper.selectById(zhuaMaDto.getId());
                if (ObjectUtil.isNotEmpty(messageLog)) {
                    continue;
                } else {
                    MessageLog messageLog1 = new MessageLog();
                    messageLog1.setId(UUID.randomUUID().toString());
                    messageLog1.setMessageId(zhuaMaDto.getId());
                    messageLog1.setCreatedOn(new Date());
                    messageLogMapper.insertMessageLog(messageLog1);
                    long startTime = zhuaMaDto.getTime() * 1000 + 60000 * 5;
                    long endTime = zhuaMaDto.getTime() * 1000 + 60000 * 10;
                    String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime))));
                    String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime))));
                    String str = zhuaMaDto.getContent();
                    String address = str.substring(str.indexOf("有宝马良驹在") + 6, str.lastIndexOf("出没！"));
                    message = message + address + "将有宝马良良驹出现   " + start + "~" + end + "\n";
                    sqlSession.commit();
                }
            }
            if (!ObjectUtils.isEmpty(message)) {
                for (GroupQu groupQu : collect1.get(fu)) {
                    System.out.println(message);

                }
            }
            sqlSession.close();
        }
    }

    //骚话爬取
    public static void main3(String[] args) throws IOException, InterruptedException {
        for (int i = 16; i <= 148; i++) {
            //获取mybatis
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //2. 获取SqlSession对象，用它来执行sql
            SqlSession sqlSession = sqlSessionFactory.openSession();
            //3. 获取mapper
            SaoHuaMapper mapper = sqlSession.getMapper(SaoHuaMapper.class);
            String s = "";
            try {
                s = HttpUtil.get("https://cms.jx3box.com/api/cms/post/jokes?per=100&page=" + String.valueOf(i) + "&type=&search=&star=");
            } catch (Exception e) {
                System.out.println("=============================================================页面页数" + i + "=======================================================");
            }
            JSONObject json = JSONObject.parseObject(s);
            if (!StringUtils.isEmpty(json.getString("data"))) {
                Map<String, Object> params = JSONObject.parseObject(json.toJSONString(), new TypeReference<Map<String, Object>>() {
                });
                Map<String, Object> data3 = (Map<String, Object>) params.get("data");
                JSONArray ja = (JSONArray) data3.get("list");
                List<MoHeSaoHua> moHeSaoHuas = ja.toJavaList(MoHeSaoHua.class);
                List<SaoHua> list = new ArrayList<>();
                for (MoHeSaoHua moHeSaoHua : moHeSaoHuas) {
                    SaoHua saoHua = new SaoHua();
                    saoHua.setId(UUID.randomUUID().toString());
                    saoHua.setText(moHeSaoHua.getContent());
                    saoHua.setCreated(new Date());
                    list.add(saoHua);
                }
                try {
                    mapper.insertList(list);
                } catch (Exception e) {
                    System.out.println("========================失败页面=====================================" + i + "=======================================================");
                    System.out.println(e.getMessage());
                    TimeUnit.SECONDS.sleep(50);
                    continue;
                }
                sqlSession.commit();
                sqlSession.close();
                TimeUnit.SECONDS.sleep(10);
            }
        }
    }

    //物品爬取
    public static void main9(String[] args) throws IOException, InterruptedException {
        for (int i = 132; i <= 377; i++) {
            //获取mybatis
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //2. 获取SqlSession对象，用它来执行sql
            SqlSession sqlSession = sqlSessionFactory.openSession();
            //3. 获取mapper
            WuPingMapper wuPingMapper = sqlSession.getMapper(WuPingMapper.class);
            //搜索物品
            Param param = QuFuUtil.getParam("souSuoWuPing");
            String s = "";
            try {
                s = HttpUtil.get(param.getValue() + "?keyword=&page=" + String.valueOf(i) + "&limit=500&client=std");
            } catch (Exception e) {
                System.out.println("=================================================失败页数============页面页数" + i + "=======================================================");
            }
            final JSONObject json = JSONObject.parseObject(s);
            if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
                Map<String, Object> params = JSONObject.parseObject(json.toJSONString(), new TypeReference<Map<String, Object>>() {
                });
                Map<String, Object> data3 = (Map<String, Object>) params.get("data");
                JSONArray ja = (JSONArray) data3.get("data");
                List<WuPing> collect = ja.toJavaList(WuPing.class);
                try {
                    wuPingMapper.insertList(collect);
                } catch (Exception e) {
                    System.out.println("=================================================失败页数============页面页数" + i + "=======================================================");
                    System.out.println(e.getMessage());
                    TimeUnit.SECONDS.sleep(50);
                    continue;
                }
            }
            sqlSession.commit();
            sqlSession.close();
            TimeUnit.SECONDS.sleep(15);
        }
    }

    //交易行查询
    public static void main1(String[] args) throws IOException, InterruptedException {

        String result = "";
        String name = "一重";
        String fu = "唯我独尊";

        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //3. 获取mapper
        WuPingMapper wuPingMapper = sqlSession.getMapper(WuPingMapper.class);
        List<WuPing> wuPings = wuPingMapper.selectByName(name);
        //搜索物品
        Param param = QuFuUtil.getParam("souSuoWuPing");
        String s = HttpUtil.get(param.getValue() + "?keyword=" + name + "&page=1&limit=50&client=std");
        JSONObject json = JSONObject.parseObject(s);
        List<WuPing> collect = new ArrayList<>();
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            Map<String, Object> params = JSONObject.parseObject(json.toJSONString());
            Map<String, Object> data3 = (Map<String, Object>) params.get("data");
            JSONArray ja = (JSONArray) data3.get("data");
            collect = ja.toJavaList(WuPing.class);
            for (WuPing wuPing : collect) {
                String id = wuPing.getId();
                WuPing wuPing1 = wuPingMapper.selectById(id);
                if (ObjectUtils.isEmpty(wuPing1)) {
                    wuPingMapper.insertWuPing(wuPing);
                }
            }
            sqlSession.commit();
        }
        sqlSession.close();
        collect.addAll(wuPings);
        collect = collect.stream().collect(Collectors.collectingAndThen(
                Collectors.toCollection(() -> new TreeSet<>(
                        Comparator.comparing(p -> p.getId()))), ArrayList::new));
        //搜索交易行
        if (collect.size() > 0) {
            List<Map<String, String>> list1 = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            map.put("0", fu);
            map.put("0", "");
            map.put("1", name);
            map.put("3", "");
            list1.add(map);

            for (int j = 0; j < collect.size(); j++) {
                result = HttpUtil.get("/api/item-price/{{itemId}}/hour-logshttps://next2.jx3box.com/api/item-price/" + collect.get(j).getId() + "/detail?server=" + fu);
                JSONObject json1 = JSONObject.parseObject(result);
                if (!ObjectUtils.isEmpty(json1.getString("msg")) && "ok".equals(json1.getString("msg")) && !StringUtils.isEmpty(json1.getString("data"))) {
                    Map<String, Object> params = JSONObject.parseObject(json1.toJSONString());
                    Map<String, Object> data3 = (Map<String, Object>) params.get("data");
                    JSONArray ja = (JSONArray) data3.get("prices");
                    if (ObjectUtils.isEmpty(ja)) {
                        continue;
                    }
                    List<PricesDto> list = ja.toJavaList(PricesDto.class);
                    if (list.size() > 0) {
                        try {
                            if (collect.size() == 1) {
                                for (PricesDto pricesDto : list) {
                                    Map<String, String> map1 = new HashMap();
                                    map1.put("0", collect.get(j).getName());
                                    map1.put("1", pricesDto.getUnit_price() / 100000000 + " Z " + (pricesDto.getUnit_price() % 100000000) / 10000 + " J");
                                    map1.put("2", pricesDto.getN_count());
                                    Long time = pricesDto.getCreated();
                                    if (time == 0) {
                                        map1.put("3", "未知");
                                    } else {
                                        Date date = new Date(time * 1000);
                                        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                        String time1 = sd.format(date);
                                        map1.put("3", time1);
                                    }
                                    list1.add(map1);
                                }
                            } else {
                                list = list.stream().sorted(Comparator.comparing(PricesDto::getUnit_price)).collect(Collectors.toList());
                                Map<String, String> map1 = new HashMap();
                                map1.put("0", collect.get(j).getName());
                                map1.put("1", list.get(0).getUnit_price() / 100000000 + " Z " + (list.get(0).getUnit_price() % 100000000) / 10000 + " J");
                                map1.put("2", list.get(0).getN_count());
                                Long time = list.get(0).getCreated();
                                if (time == 0) {
                                    map1.put("3", "未知");
                                } else {
                                    Date date = new Date(time * 1000);
                                    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                    String time1 = sd.format(date);
                                    map1.put("3", time1);
                                }
                                list1.add(map1);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }

            UUID uuid = UUID.randomUUID();
            String path = "src/main/resources/image/" + uuid.toString() + ".jpg";
            generateSizeImageJiaoYiHang(list1, path, "不要频繁发起查询哦！");
            //发送图片
            PathResource resource1 = Resource.of(Paths.get(path));
            MiraiSendOnlyImage sendOnlyImage = MiraiSendOnlyImage.of(resource1);
            System.out.println(path);
            return;
        }
        System.out.println("查询不到物品 检查名称是否正确");
    }

    //定时抓马查询
    public static void main7(String[] args) throws IOException, InterruptedException {
        //获取已获取群聊
        List<Group> groupList = MyGroupListener.groupList;
        List<Long> idList = groupList.stream().map(p -> ((LongID) p.getId()).getNumber()).collect(Collectors.toList());
        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //3. 获取mapper
        GroupQuMapper groupQuMapper = sqlSession.getMapper(GroupQuMapper.class);
        List<GroupQu> groupQuList = groupQuMapper.selectAllById(idList);

        Map<String, List<GroupQu>> collect1 = groupQuList.stream().collect(Collectors.groupingBy(p -> p.getQu(), Collectors.toList()));
        Set<String> fuList = collect1.keySet();
        for (String fu : fuList) {
            Param param = QuFuUtil.getParam("zhuama");
            String url = param.getValue() + "?pageIndex=1&pageSize=50&server=" + fu + "&type=horse";
            String result = HttpUtil.get(url);
            final JSONObject json = JSONObject.parseObject(result);
            String data = json.getString("data");
            final JSONObject json1 = JSONObject.parseObject(data);
            String list = json1.getString("list");
            List<ZhuaMaDto> zhuaMaDtoList = (List<ZhuaMaDto>) JSONArray.parseArray(list, ZhuaMaDto.class);

            String message = "";
            //获取时间戳(十分钟前的)
            long time = System.currentTimeMillis() - 60000 * 10;
            List<ZhuaMaDto> collect = zhuaMaDtoList.stream().filter(p -> "zhcn_hd".equals(p.getEdition()) && p.getTime() * 1000 > time).collect(Collectors.toList());
            //5-10分钟播报
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            for (ZhuaMaDto zhuaMaDto : collect) {
                long startTime = zhuaMaDto.getTime() * 1000 + 60000 * 5;
                long endTime = zhuaMaDto.getTime() * 1000 + 60000 * 10;
                String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime))));
                String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime))));
                String str = zhuaMaDto.getContent();
                String address = str.substring(str.indexOf("有宝马良驹在") + 6, str.lastIndexOf("出没！"));
                message = message + address + "将有宝马良良驹出现   " + start + "~" + end + "\n";
            }
            if (!ObjectUtils.isEmpty(message)) {
                for (GroupQu groupQu : collect1.get(fu)) {
                    List<Group> collect2 = groupList.stream().filter(p -> p.getId().equals(groupQu.getGroupId())).collect(Collectors.toList());
                    for (Group group : collect2) {
                        group.sendBlocking(message);
                    }
                }
            }
        }
    }

    //抓马查询
    public static void main8(String[] args) throws IOException, InterruptedException {
        Param param = QuFuUtil.getParam("zhuama");
        String url = param.getValue() + "?pageIndex=1&pageSize=50&server=梦江南&type=horse";
        String result = HttpUtil.get(url);
        final JSONObject json = JSONObject.parseObject(result);
        String data = json.getString("data");
        final JSONObject json1 = JSONObject.parseObject(data);
        String list = json1.getString("list");
        List<ZhuaMaDto> zhuaMaDtoList = (List<ZhuaMaDto>) JSONArray.parseArray(list, ZhuaMaDto.class);

        String message = "";
        //获取时间戳(十分钟前的)
        long time = System.currentTimeMillis() - 60000 * 10;
        List<ZhuaMaDto> collect = zhuaMaDtoList.stream().filter(p -> "zhcn_hd".equals(p.getEdition()) && p.getTime() * 1000 > time).collect(Collectors.toList());
        //5-10分钟播报
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        for (ZhuaMaDto zhuaMaDto : collect) {
            long startTime = zhuaMaDto.getTime() * 1000 + 60000 * 5;
            long endTime = zhuaMaDto.getTime() * 1000 + 60000 * 10;
            String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime))));
            String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime))));
            String str = zhuaMaDto.getContent();
            String address = str.substring(str.indexOf("有宝马良驹在") + 6, str.lastIndexOf("出没！"));
            message = message + address + "将有宝马良良驹出现   " + start + "~" + end + "\n";
        }

        //npcChat
        String yinShanDaCaoYuan = "阴山大草原马场：\n";
        ZhuaMaDto yinShan = zhuaMaDtoList.stream().filter(p -> "216".equals(p.getMap_id())).collect(Collectors.toList()).get(0);
        String[] split = yinShan.getContent().split("\n");
        for (String str : split) {
            if (str.contains("分钟")) {
                String horse = str.substring(str.indexOf("下一匹") + 3, str.lastIndexOf("出世"));
                String fenZhong = str.substring(str.indexOf("还有") + 2, str.lastIndexOf("分钟"));
                long startTime = yinShan.getTime() * 1000 + 60000 * (Long.parseLong(fenZhong) + 5);
                long endTime = yinShan.getTime() * 1000 + 60000 * (Long.parseLong(fenZhong) + 10);

                String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime))));
                String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime))));
                if (System.currentTimeMillis() < endTime) {
                    yinShanDaCaoYuan = yinShanDaCaoYuan + horse + "   时间" + start + "~" + end + "\n";
                }
            }
        }
        if (!"阴山大草原马场：\n".equals(yinShanDaCaoYuan)) {
            message = message + yinShanDaCaoYuan;
        }

        String heiGeBiMaChang = "黑戈壁马场：\n";
        ZhuaMaDto heiGeBi = zhuaMaDtoList.stream().filter(p -> "217".equals(p.getMap_id())).collect(Collectors.toList()).get(0);
        String[] split1 = heiGeBi.getContent().split("\n");
        for (String str : split1) {
            if (str.contains("分钟")) {
                String horse = str.substring(str.indexOf("下一匹") + 3, str.lastIndexOf("出世"));
                String fenZhong = str.substring(str.indexOf("还有") + 2, str.lastIndexOf("分钟"));
                long startTime = heiGeBi.getTime() * 1000 + 60000 * (Long.parseLong(fenZhong) + 5);
                long endTime = heiGeBi.getTime() * 1000 + 60000 * (Long.parseLong(fenZhong) + 10);
                String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime))));
                String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime))));
                if (System.currentTimeMillis() < endTime) {
                    heiGeBiMaChang = heiGeBiMaChang + horse + "   时间" + start + "~" + end + "\n";
                }
            }
        }
        if (!"黑戈壁马场：\n".equals(heiGeBiMaChang)) {
            message = message + heiGeBiMaChang;
        }
        System.out.println(message);
    }

    //奇穴魔盒置换
    public static void main6(String[] args) throws IOException, InterruptedException {
        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3. 获取mapper
        MoHeDataMapper moHeDataMapper = sqlSession.getMapper(MoHeDataMapper.class);
        List<MoHeData> moHeData = moHeDataMapper.selectAll();


        String result = HttpUtil.get("https://data.jx3box.com/talent/v20230427.json");
        final JSONObject json = JSONObject.parseObject(result);
        Map<String, Object> params = JSONObject.parseObject(json.toJSONString(), new TypeReference<Map<String, Object>>() {
        });

        for (MoHeData moHeDatum : moHeData) {
            String talent = moHeDatum.getTalent();
            if (ObjectUtils.isEmpty(talent)) {
                continue;
            }
            Map<String, String> jsonMap = JSON.parseObject(talent, new TypeReference<HashMap<String, String>>() {
            });
            String xf = jsonMap.get("xf");
            String s1 = jsonMap.get("sq");
            String[] split = s1.split(",");
            Map<String, Object> o = (Map<String, Object>) params.get(xf);

            String qixue = "";
            for (int i = 0; i < split.length; i++) {
                String index = String.valueOf(i + 1);
                Map<String, Object> map = (Map<String, Object>) o.get(index);
                Map<String, Object> o1 = (Map<String, Object>) map.get(split[i]);
                qixue = qixue + " " + o1.get("name").toString();
            }
            moHeDatum.setQixue(qixue);
            moHeDataMapper.update(moHeDatum);
            sqlSession.commit();
        }
        sqlSession.close();
    }

    //魔盒爬虫
    public static void main5(String[] args) throws IOException, InterruptedException {

        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3. 获取mapper
        MoHeDataMapper moHeDataMapper = sqlSession.getMapper(MoHeDataMapper.class);
        String[] string = {"21518", "57540", "45645", "31682", "46213", "47165", "58448", "243", "20100", "21622", "57892", "35573", "45971", "19704", "58147", "57645"};
        for (String s : string) {
            TimeUnit.SECONDS.sleep(10);
            //获取参数
            String result = HttpUtil.get("https://cms.jx3box.com/api/cms/post/" + s);
            //返回参数处理
            final JSONObject json = JSONObject.parseObject(result);
            System.out.println(s);
            if (!ObjectUtils.isEmpty(json.getString("msg")) && "Success".equals(json.getString("msg")) && !StringUtils.isEmpty(json.getString("data"))) {
                Map<String, Object> params = JSONObject.parseObject(json.toJSONString(), new TypeReference<Map<String, Object>>() {
                });
                Map<String, Object> data3 = (Map<String, Object>) params.get("data");
                String postSubtype = data3.get("post_subtype").toString();
                JSONObject postMeta1 = (JSONObject) data3.get("post_meta");
                JSONArray ja = postMeta1.getJSONArray("data");
                List<MoHeData> collect = ja.toJavaList(MoHeData.class);
                for (MoHeData moHeData : collect) {
                    moHeData.setId(UUID.randomUUID().toString());
                    moHeData.setZhiye(postSubtype);
                    moHeDataMapper.save(moHeData);
                }
                sqlSession.commit();
            }

        }
        sqlSession.close();
    }

    public static void main20(String[] args) throws IOException {

        String result = HttpUtil.get("https://www.jx3api.com/data/active/current?server=唯我独尊&num=");
        //返回参数处理
        final JSONObject json = JSONObject.parseObject(result);
        if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
            TotalDto totalDto = json.getObject("data", TotalDto.class);
            String[] split = totalDto.getDate().split("-");
            //家园声望
            String pre = "";
            if (ObjectUtil.isNotEmpty(totalDto.getPrestige())) {
                String[] prestige = totalDto.getPrestige();
                pre = String.join("、", prestige);
            }
            //武林通鉴
            String[] team = totalDto.getTeam();
            String team1 = String.join("\n", team);
            //美人图
            String huatu = "";
            if (!ObjectUtils.isEmpty(totalDto.getHuatu())) {
                huatu = "美人图∶" + totalDto.getHuatu() + "\n";
            }

            System.out.println("今天是" + split[0] + "年" + split[1] + "月" + split[2] + "日星期" + totalDto.getWeek() + "\n" +
                    "阵营∶跨服·烂柯山\n" +
                    "战场∶" + totalDto.getBattle() + "\n" +
                    "大战∶" + totalDto.getWar() + "\n" +
                    "家园声望∶" + pre + "\n" +
                    "武林通鉴∶" + team1 + "\n"
                    + huatu +
                    "活动∶" + totalDto.getSchool() + "\n");
        } else {
        }
    }


    public static void main2(String[] args) throws IOException {
        //获取mybatis
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3. 获取mapper
        ParamMapper paramMapper = sqlSession.getMapper(ParamMapper.class);

        String result = HttpUtil.get("https://www.jx3api.com/data/luck/adventure?server=唯我独尊&name=颜麓&token=v1deab45dcd82967a3");
        if (!StringUtils.isEmpty(result)) {
            final JSONObject json = JSONObject.parseObject(result);
            if (!ObjectUtils.isEmpty(json.getString("code")) && "200".equals(json.getString("code")) && !StringUtils.isEmpty(json.getString("data"))) {
                JSONArray ja = json.getJSONArray("data");
                List<QiYuDto> collect = ja.toJavaList(QiYuDto.class);
                List<QiYuDto> list = collect.stream().filter(p -> !"3".equals(p.getLevel())).collect(Collectors.toList());
                try {
                    String[][] tableData2 = new String[list.size() + 1][3];
                    tableData2[0][0] = "唯我独尊";
                    tableData2[0][1] = "颜麓";
                    for (int i = 0; i < list.size(); i++) {
                        tableData2[i + 1][0] = list.get(i).getName();
                        tableData2[i + 1][1] = list.get(i).getEvent();
                        Long time = list.get(i).getTime();
                        Date date = new Date(time * 1000);
                        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String time1 = sd.format(date);
                        tableData2[i + 1][2] = time1;
                    }
                    UUID uuid = UUID.randomUUID();
                    generateSizeImage(tableData2, "D:/image/" + uuid.toString() + ".jpg", "不要频发发起查询哦！");
                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
            }
        } else {

        }
    }
}

